<?php

namespace App\Model;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class CabinPearlStream extends BaseModel
{
    protected $table = 'cabin_pearl_stream';
    public $timestamps = false;

  //

    public function getCabinStreamToRoomId($room_id)
    {
        $date = date('Y-m-d');
        $dayTime[] = date('Y-m-d 00:00:00', time());
        $dayTime[] = date('Y-m-d 23:59:59', time());
        $upWeek = date('Y-m-d', strtotime("$date -7 day"));
        $weekTime = $this->getAWeekTimeSlot($date);//本周
        $upweekTime = $this->getAWeekTimeSlot($upWeek);//上周
        $monthTime[] = date('Y-m-01 00:00:00',time());
        $monthTime[] = date('Y-m-t 23:59:59',time());
        $upMonthTime[] = date('Y-m-01 00:00:00',strtotime("$date -1 month"));
        $upMonthTime[] = date('Y-m-t 23:59:59',strtotime("$date -1 month"));
        dd($upweekTime);
    }

    function getAWeekTimeSlot($gdate = '', $weekStart = 1)
    {
        if (!$gdate) {
            $gdate = date("Y-m-d");
        }
        $w = date("w", strtotime($gdate)); //取得一周的第几天,星期天开始0-6
        $dn = $w ? $w - $weekStart : 6; //要减去的天数
        $time[] = date("Y-m-d 00:00:00", strtotime("$gdate  - " . $dn . "  days "));
        $time[] = date("Y-m-d 23:59:59", strtotime("$time[0]  +6  days "));
        return $time; //返回开始和结束日期

    }
}
